{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# RWTH Colors\n", "\n", "When using `rwth_nb.plots.colors`, the RWTH [Corporate Design](http://www.rwth-aachen.de/cms/root/Die-RWTH/Einrichtungen/Verwaltung/Stabsstellen/Marketing/~eqbm/Corporate-Design/) color scheme is stored in a dictionary called `rwth_colors`. When loading `rwth_nb.plots.mpl_decorations`, the RWTH colors are propagated to Matplotlib as well. The following colors may be used:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "from rwth_nb.plots import colors\n", "\n", "# adapted from https://matplotlib.org/2.0.0/examples/color/named_colors.html\n", "colors = colors.rwth_colors;\n", "fontsize = 12\n", "ncols = 5; nrows = len(colors.keys()) // ncols + 1;\n", "\n", "fig, ax = plt.subplots(figsize=(12, 6))\n", "X, Y = fig.get_dpi() * fig.get_size_inches() # Get height and width\n", "w = X / ncols; h = Y / nrows\n", "\n", "for i, name in enumerate(colors.keys()):\n", " col = i % ncols\n", " row = i // ncols\n", " y = Y - (row * h) - h\n", "\n", " xi_line = w * (col + 0.05); xf_line = w * (col + 0.25); xi_text = w * (col + 0.3)\n", " ax.text(xi_text, y, name, fontsize=fontsize, horizontalalignment='left', verticalalignment='center')\n", " ax.hlines(y + h * 0.1, xi_line, xf_line, color=colors[name], linewidth=(h * 0.6))\n", "\n", "ax.set_xlim(0, X); ax.set_ylim(0, Y); ax.set_axis_off();\n", "fig.subplots_adjust(left=0, right=1, top=1, bottom=0, hspace=0, wspace=0)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "When plotting, colors are cycled through for each graph by following order: \n", "> *blue, orange, green, red, purple, bordeaux, violet, black-50, maigrun, turquoise*" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import rwth_nb.plots.mpl_decorations as rwth_plt\n", "\n", "x = np.linspace(-2, 2, 501)\n", "\n", "fig, ax = plt.subplots()\n", "ax.set_ylim(-2, 2)\n", "rwth_plt.axis(ax); rwth_plt.grid(ax)\n", "\n", "for n in range(10):\n", " ax.plot(x, x**n, label=r'$x^{}$'.format(n))\n", " \n", "ax.legend();" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For custom coloring, use as below." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import rwth_nb.plots.mpl_decorations as rwth_plt\n", "\n", "x = np.linspace(-4,4);\n", "\n", "fig,ax = plt.subplots();\n", "ax.plot(x, x**2, 'rwth:blue');\n", "ax.plot(x, x**2 + np.random.randn(len(x)), '.', color='rwth:green');" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This code is licensed under the [MIT license](https://opensource.org/licenses/MIT)." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.2" } }, "nbformat": 4, "nbformat_minor": 4 }